package com.junzhiit.nengji.api.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.bainaeco.framework.util.AssertUtil;
import com.junzhiit.nengji.api.service.FavoriteService;
import com.junzhiit.nengji.api.web.vo.ResultVO;

import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/favorite")
public class FavoriteController extends BaseController {
	

	@Autowired
	private FavoriteService favoriteService;
	
	@ApiOperation(value = "收藏商品")
	@RequestMapping(method = RequestMethod.POST)
	public ResultVO add(String goodsId,String userId){
		AssertUtil.notBlank(userId, "userId is required.");
		AssertUtil.notBlank(goodsId, "goodsId is required.");
		return favoriteService.add(goodsId,userId);
	}
	
	@ApiOperation(value = "批量收藏商品")
	@RequestMapping(value="/batch",method = RequestMethod.POST)
	public ResultVO addBatch(String goodsId[],String userId){
		AssertUtil.notBlank(userId, "userId is required.");
		return favoriteService.addBatch(goodsId,userId);
	}
	
	@ApiOperation(value = "取消收藏")
	@RequestMapping(method = RequestMethod.PUT)
	public ResultVO delete(String userId,String[] favoriteId){
		AssertUtil.notBlank(userId, "userId is required.");
		return favoriteService.delete(userId, favoriteId);
	}
	
	@ApiOperation(value = "查询收藏商品")
	@RequestMapping(method = RequestMethod.GET)
	public ResultVO get(Integer pageNumber,Integer maxPageRow,String userId){
		AssertUtil.notNull(pageNumber, "pageNumber is required.");
		AssertUtil.notNull(maxPageRow, "maxPageRow is required.");
		AssertUtil.notBlank(userId, "userId is required.");
		return favoriteService.getFavorite(pageNumber,maxPageRow,userId);
	}
}
